$("#fh").click(function () {
    window.location = '../../../login.html';
})
$("#sx").click(function () {
    window.location = 'customerServiceManagement.html';
})

function  refre(){
    customerServiceManagementtableI.reload('customerServiceManagementtableId');
}
var customerServiceManagementtableI = null;
layui.use(['table', 'laydate','form'], function(){
    var table = layui.table,
        laydate = layui.laydate,
        form = layui.form,
        data = null;
    laydate.render({
        elem: '#rq', //指定元素
    });

    customerServiceManagementtableI = table.render({
        elem: '#test'
        ,url:'/customerServiceManagement/getAll'
        ,id:'customerServiceManagementtableId'
        ,page:{
            limit:10,
            limits:[10,12,14],
            layout:['count','prev','page','next','limit'],
            groups:2
        }
        ,cols: [
            [
                {type: 'checkbox', fixed: 'left'}
                ,{field:'cusSerId', width:100, title: '序号', sort: true}
                ,{field:'sender', width:200, title: '发送人'}
                ,{field:'receiver', width:200, title: '接收人'}
                ,{field:'messageContent', width:200, title: '消息内容'}
                ,{field:'sentOnTime', title: '发送时间',  width: 250}
                ,{field:'sendType', title: '类型',  width: 100}
                ,{fixed: '', title:'操作',align:'center', minWidth: 180,toolbar: '#barDemo'}
            ]
        ],
        skin: 'line',
        parseData:function (res){
            return{
                "code":res.code, // 解析接口状态
                "msg": res.msg, // 解析提示文本
                "count": res.count, // 解析总条数
                "data": res.data // 解析数据列表
            };
        }
    });

    table.on('tool(test)', function(obj){ // 双击 toolDouble
        data = obj.data;
        //console.log(obj)
        if(obj.event === 'del'){
            layer.confirm('真的删除行么', function(index){
                // layer.close(index);
                $.ajax({
                    type:"post",
                    url:'/customerServiceManagement/del',
                    data: {"cusSerId":data.cusSerId},
                    dataType:'json',
                    success:function (res) {
                        if (res.state == 200){
                            layer.msg(res.msg,{time:500,icon:6});
                            refre();
                        }
                        else {
                            layer.msg(res.msg,{time:500,icon:5})
                        }
                    },
                    error:function(e){
                        console.log("异常");

                    }

                })

            });
        }else if(obj.event === 'required'){
            // alert("序号:"+data.deptId+"是否启用:"+data.deptState);
            switch (data.deptState) {
                case "启用":
                    qy("不启用");
                    break;
                case "不启用":
                    qy("启用")
                    break;
            }
        }

    });

    form.on('submit(go)',function (d){
        d = d.field;
        // console.log(d);
        table.reload('departmenttableId',{
            where:{
                deptName:d.deptName
                ,admintorName:d.admintorName
                ,deptCreatdate:d.deptCreatdate
                ,deptState:d.deptState
            }
        });
    })
    function qy(sta) {
        $.ajax({
            type:"post",
            url:'/department/updState',
            data: {"deptId":data.deptId,"deptState":sta},
            dataType:'json',
            success:function (res) {
                if (res.start == 200){
                    layer.msg(res.msg,{time:500,icon:6})
                }
                else {
                    layer.msg("失败",{time:500,icon:5})
                }
            },
            error:function(e){
                console.log("异常");

            }

        })
    }
});
